package com.jzo2o.customer.controller.consumer;

import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.customer.model.domain.AddressBook;
import com.jzo2o.customer.model.dto.request.AddressBookPageQueryReqDTO;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO
 *
 * @Author ljy
 * @Date 2024/12/2 15:21
 */
@RestController("consumerAddressController")
@RequestMapping("/consumer/address-book")
@Api(tags = "用户端 - 用户地址相关接口")
public class AddressController {
    @Autowired
    private IAddressBookService addressBookService;
    @PostMapping
    @ApiOperation("新增地址")
    public void addAddressBook(@RequestBody AddressBookUpsertReqDTO dto){
        addressBookService.addAddressBook(dto);
    }
    @GetMapping("/page")
    @ApiOperation("地址分页查询")
    public PageResult<AddressBookResDTO> page(AddressBookPageQueryReqDTO dto){
       return addressBookService.page(dto);
    }
    @GetMapping("/{id}")
    @ApiOperation("根据id查询地址详情")
    public AddressBook getById(@PathVariable("id") Long id){
        return addressBookService.getById(id);
    }
    @PutMapping("/{id}")
    @ApiOperation("修改地址")
    public void updateAddress(@RequestBody AddressBookUpsertReqDTO dto,@PathVariable("id") Long id){
        addressBookService.updateAddress(dto,id);
    }
    @ApiOperation("批量删除")
    @DeleteMapping("/batch")
    public void batch(@RequestBody List<String> ids){
        addressBookService.deleteBatch(ids);
    }
    @PutMapping("/default")
    @ApiOperation("设置或者取消默认地址")
    public void isDefault(@RequestParam("id") Long id,@RequestParam("flag") Integer flag){
        addressBookService.setDefault(id,flag);
    }
    @GetMapping("/defaultAddress")
    @ApiOperation("获取默认地址")
    public AddressBook getdefaultAddress(){
        return addressBookService.getdefaultAddress();
    }
}